home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / MacPNG Library 1.02 / pngMacSrc 1.02 / PNG Library 0.80 / PNGIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-29  |  2.7 KB  |  73 lines  |  [TEXT/CWIE]

  1.  
  2. /* pngstub.c - stub functions for i/o and memory allocation
  3.  
  4.    libpng 1.0 beta 2 - version 0.8
  5.    For conditions of distribution and use, see copyright notice in png.h
  6.    Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
  7.    August 20, 1995
  8.  
  9.    This file provides a location for all input/output.  Users which need
  10.    special handling are expected to modify the code in this file to meet
  11.    their needs.  See the instructions at each function. */
  12.  
  13. #define PNG_INTERNAL
  14. #include "png.h"
  15.  
  16. /* Write the data to whatever output you are using.  The default
  17.    routine writes to a file pointer.  If you need to write to something
  18.    else, this is the place to do it.  We suggest saving the old code
  19.    for future use, possibly in a #define.  Note that this routine sometimes
  20.    gets called with very small lengths, so you should implement some kind
  21.    of simple buffering if you are using unbuffered writes.  This should
  22.    never be asked to write more then 64K on a 16 bit machine.  The cast
  23.    to png_size_t is there for insurance, but if you are having problems
  24.    with it, you can take it out.  Just be sure to cast length to whatever
  25.    fwrite needs in that spot if you don't have a function prototype for
  26.    it. */
  27. void
  28. png_write_data(png_struct *png_ptr, png_byte *data, png_uint_32 length)
  29. {
  30.    png_uint_32 check;
  31.  
  32.    check = fwrite(data, 1, (png_size_t)length, png_ptr->fp);
  33.    if (check != length)
  34.    {
  35.       png_error(png_ptr, "Write Error");
  36.    }
  37. }
  38.  
  39. /* Read the data from whatever input you are using.  The default
  40.    routine reads from a file pointer.  If you need to read from something
  41.    else, this is the place to do it.  We suggest saving the old code
  42.    for future use.  Note that this routine sometimes gets called with
  43.    very small lengths, so you should implement some kind of simple
  44.    buffering if you are using unbuffered reads.  This should
  45.    never be asked to read more then 64K on a 16 bit machine.  The cast
  46.    to png_size_t is there for insurance, but if you are having problems
  47.    with it, you can take it out.  Just be sure to cast length to whatever
  48.    fread needs in that spot if you don't have a function prototype for
  49.    it. */
  50. void
  51. png_read_data(png_struct *png_ptr, png_byte *data, png_uint_32 length)
  52. {
  53.    png_uint_32 check;
  54.  
  55.    check = fread(data, 1, (size_t)length, png_ptr->fp);
  56.    if (check != length)
  57.    {
  58.       png_error(png_ptr, "Read Error");
  59.    }
  60. }
  61.  
  62. /* Initialize the input/output for the png file.  If you change
  63.    the read and write routines, you will probably need to change
  64.    this routine (or write your own).  If you change the parameters
  65.    of this routine, remember to change png.h also. */
  66. void
  67. png_init_io(png_struct *png_ptr, FILE *fp)
  68. {
  69.    png_ptr->fp = fp;
  70. }
  71.  
  72.  
  73.